import java.util.List;
import java.util.LinkedList;

public class Production{
    private List<Simbol> simbols;
    private List<SintaxRule> srsimbols;

    public Production (){
		this.simbols=new LinkedList<Simbol>();
		this.srsimbols=new LinkedList<SintaxRule>();
    }
    
    public List<Simbol> getSimbols(){
		return this.simbols;
    }

    public void addSimbol(Simbol s){
		this.simbols.add(s);
    }
    
    public List<SintaxRule> getSRSimbols(){
		return this.srsimbols;
    }

    public void addSRSimbol(SintaxRule sr){
		this.srsimbols.add(sr);
    }

    public void addTerms(List<Simbol> simbols, List<SintaxRule> srsimbols){
		SintaxRule sr;
		Simbol s;
		int srsize=this.srsimbols.size(), ssize=this.simbols.size();
		for(int i=0;i<srsimbols.size();i++){
		    sr=srsimbols.get(i);
		    sr.setPosition(sr.getPosition()+srsize);
		    this.srsimbols.add(sr);
		}

		for(int i=0;i<simbols.size();i++)
		    this.simbols.add(simbols.get(i));
	
	}

/*	public String toString(){
		int length=simbols.size()+srsimbols.size();
		String s="";
		for(int i=0;i<length;i++){
			for(int j=0;j<srsimbols.size() && srsimbols.size()>i;j++){
				if(srsimbols.get(i).getPosition()==i){
					s+=srsimbols.get(i).toString();
				}
			}

			if(i<simbols.size())s+=simbols.get(i).toString();
			
		}

		return c;	
	}*/

    public String toString(){
	int length=simbols.size()+srsimbols.size();
	int size=simbols.size()-1;
	String s="";
	
	if(simbols.size()>0 || srsimbols.size()>0){
	    for(int i=length;i>=0;i--){
		for(int j=0;j<srsimbols.size();j++){
		    if(srsimbols.get(j).getPosition()==(length-i)){
			s+=srsimbols.get(j).toString();
		    }
		}

		if(size>=0)s+=simbols.get(size--).toString();
			
	    }
	}

	return s;	
    }
	
}
